package com.sks.bean.uploadfile;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;

import com.sks.bean.pojo.Building;
import com.sks.bean.pojo.House;
import com.sks.utils.StringUtil;

/**
 * UploadFile entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "upload_file", uniqueConstraints = {})
public class UploadFile implements java.io.Serializable {
	
   public static final String SLASH = "/";
   
   public static final int SMALL_SIZE = 391;
   
   public static final int BIG_SIZE = 750;

   // Fields    

   private Integer fileId;
   private String name;
   private String path;
   private String objType;
   private Integer objId;
   private Date uploadTime;
   private String extension;
   private Integer size;
   private String remark;
   
   private Building building;
   private House house;

   // Constructors

   /** default constructor */
   public UploadFile() {
   }

   /** minimal constructor */
   public UploadFile(String name, String path) {
      this.name = name;
      this.path = path;
   }

   /** full constructor */
   public UploadFile(Integer fileId, String name, String path, String objType,
         Integer objId, Date uploadTime, String extension, Integer size,
         String remark) {
      this.fileId = fileId;
      this.name = name;
      this.path = path;
      this.objType = objType;
      this.objId = objId;
      this.uploadTime = uploadTime;
      this.extension = extension;
      this.size = size;
      this.remark = remark;
   }

   // Property accessors
   @Id
   @GeneratedValue(strategy = IDENTITY)
   @Column(name = "fileId", unique = true, nullable = false, insertable = true, updatable = true)
   public Integer getFileId() {
      return this.fileId;
   }

   public void setFileId(Integer fileId) {
      this.fileId = fileId;
   }

   @Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }

   @Column(name = "path", unique = false, nullable = false, insertable = true, updatable = true, length = 200)
   public String getPath() {
      return this.path;
   }

   public void setPath(String path) {
      this.path = path;
   }

   @Column(name = "objType", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
   public String getObjType() {
      return this.objType;
   }

   public void setObjType(String objType) {
      this.objType = objType;
   }

   @Column(name = "objId", unique = false, nullable = true, insertable = true, updatable = true)
   public Integer getObjId() {
      return this.objId;
   }

   public void setObjId(Integer objId) {
      this.objId = objId;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "uploadTime", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
   public Date getUploadTime() {
      return this.uploadTime;
   }

   public void setUploadTime(Date uploadTime) {
      this.uploadTime = uploadTime;
   }

   @Column(name = "extension", unique = false, nullable = true, insertable = true, updatable = true, length = 8)
   public String getExtension() {
      return this.extension;
   }

   public void setExtension(String extension) {
      this.extension = extension;
   }

   @Column(name = "size", unique = false, nullable = true, insertable = true, updatable = true)
   public Integer getSize() {
      return this.size;
   }

   public void setSize(Integer size) {
      this.size = size;
   }

   @Column(name = "remark", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
   public String getRemark() {
      return this.remark;
   }

   public void setRemark(String remark) {
      this.remark = remark;
   }
   @JsonIgnore
   @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
   @JoinColumn(name = "objId", unique = false, nullable = true, insertable = false, updatable = false)
   public House getHouse() {
      return house;
   }

   public void setHouse(House house) {
	   this.house = house;
   }
   @JsonIgnore
   @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
   @JoinColumn(name = "objId", unique = false, nullable = true, insertable = false, updatable = false)
   public Building getBuilding() {
	   return building;
   }

   public void setBuilding(Building building) {
	   this.building = building;
   }
   
   @Transient
   public String getFullPathName() {
	   if (StringUtil.isEmpty(this.getPath())
			   || StringUtil.isEmpty(this.getName())
			   || StringUtil.isEmpty(this.getExtension())) {
		   return null;
	   }
	   return this.getPath() + SLASH + this.getName() + "." + this.getExtension();
   }
   
   @Transient
   public String getSmallFullPathName() {
	   if (StringUtil.isEmpty(this.getPath())
			   || StringUtil.isEmpty(this.getName())
			   || StringUtil.isEmpty(this.getExtension())) {
		   return null;
	   }
	   return this.getPath() + SLASH + SMALL_SIZE + SLASH + this.getName() + "." + this.getExtension();
   }
}